package com.hy.erp.inventory.service;

import java.util.List ;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

/*import javax.ejb.Stateless ;

import org.jboss.seam.ScopeType ;
import org.jboss.seam.annotations.Name ;
import org.jboss.seam.annotations.Scope ;
import org.jboss.seam.async.Schedule ;
*/
import com.hy.enterprise.architecture.foundation.ArchitectureFoundationException;
import com.hy.enterprise.framework.service.business.AbstractBusinessService;
import com.hy.erp.inventory.dao.UnitTypeDao;
import com.hy.erp.inventory.dao.interfaces.IUnitNameDao;
import com.hy.erp.inventory.dao.interfaces.IUnitTypeDao;
import com.hy.erp.inventory.dao.interfaces.IUserDao;
import com.hy.erp.inventory.dao.interfaces.IWorkingDao;
import com.hy.erp.inventory.pojo.UnitType;
import com.hy.erp.inventory.pojo.Working;
import com.hy.erp.inventory.pojo.interfaces.IUnitName;
import com.hy.erp.inventory.pojo.interfaces.IUnitType;
import com.hy.erp.inventory.pojo.interfaces.IUser;
import com.hy.erp.inventory.pojo.interfaces.IWorking;
import com.hy.erp.inventory.service.interfaces.IUnitTypeService;
/*@Name("unitTypeService")
@ Scope ( ScopeType.STATELESS )
@ Stateless*/
@Component("unitTypeService")
public class UnitTypeService
							extends
							AbstractBusinessService < UnitTypeDao >
																	implements
																	IUnitTypeService
{

	/**
	 * <ul>
	 * <li>开发作者：汤莉</li>
	 * <li>设计日期：2010-10-11；时间：下午04:24:31</li>
	 * <li>字段类型：long；字段名称：serialVersionUID</li>
	 * <li>设计目的：</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 */
	private static final long	serialVersionUID	=
														854866883916645238L ;

	private IUnitTypeDao unitTypeDao=null;
	
	@Resource(name="unitTypeDao")
	public void setUnitTypeDao(IUnitTypeDao unitTypeDao) {
		this.unitTypeDao = unitTypeDao;
	}
	
	
	public UnitTypeService(){
		super ( );
	}
	
	@ Override
	public boolean addUnitType (
									UnitType unitType )
	{
		if(unitType==null)
		{
			return true;
		}
		else
		{
			//IUnitTypeDao dao=( IUnitTypeDao ) this.getDao ( IUnitType.class );
			//IUnitType iUnitType= unitType;
			return unitTypeDao.persist (unitType ) ;
		}
	}

	@Override
	public Integer removeUnitType(String[] unitTypeIds) {
		if ( ( null == unitTypeIds )
			     || ( unitTypeIds.length == 0 ) )
			{
				return new Integer (
				                     0 ) ;
			}
			else
			{
				//IUnitTypeDao dao=( IUnitTypeDao ) this.getDao ( IUnitType.class );
				return unitTypeDao.remove ( unitTypeIds );
			}
	}

	@SuppressWarnings("unused")
	@Override
	public boolean modifyUnitType(UnitType unitType) {
		if ( ( null == unitType ) || ( null == unitType.getIdentifier ( ) ))
		{
			return true;
		}
		else
		{
		//	IUnitTypeDao dao=( IUnitTypeDao ) this.getDao ( IUnitType.class );
		//	IUnitType iUnitType= unitType;
			
			if ( null == unitType )
			{
				throw new ArchitectureFoundationException (
				                                            "修改用户实体数据时发生错误，所需要修改的实体在数据库中并不存在" ) ;
			}
			return (unitTypeDao.merge ( unitType )!=null) ;
		}
	}

	@ Override
	public String [ ] addUnitType (
									Object [ ] objects )
	{
		//IUnitTypeDao dao=( IUnitTypeDao ) this.getDao ( IUnitType.class );
		UnitType[] types=new UnitType[objects.length];
		for(int i=0;i<objects.length;i++)
		{
			UnitType type=( UnitType ) objects[i];
			types[i]=type;
		}
		return unitTypeDao.persist ( types ) ;
	}

	@ Override
	public List < UnitType > getAllUnitType ( )
	{
	//	IUnitTypeDao dao=( IUnitTypeDao ) this.getDao ( IUnitType.class );
		return unitTypeDao.find ( ) ;
	}

	@ Override
	public String [ ] modifyUnitType (
										Object [ ] objects )
	{
		if (  null == objects ) 
		{
			return null;
		}
		else
		{
	//		IUnitTypeDao dao=( IUnitTypeDao ) this.getDao ( IUnitType.class );
			UnitType[] types=new UnitType[objects.length];
            for(int i=0;i<objects.length;i++)
            {
            	UnitType type=( UnitType ) objects[i];
            	types[i]=type;
            }
			
			return unitTypeDao.merge ( types );
		}
	}

}
